<div class="page-header">
    <h1>
        Withdraw
        <small>
            <i class="icon-double-angle-right"></i>
            Withdraw Report
        </small>
    </h1>
</div>

<div class="row">
    <div class="col-xs-11">
        <!-- PAGE CONTENT BEGINS -->
        <form id="frm" class="form-horizontal" role="form" action="" method="post">
            
                <div class="form-group">
                    <label class="col-sm-2 control-label no-padding-right" for="date1">Period</label>
                    <div class="col-sm-7">
                        <input type="text" class="easyui-text" style="width:150px" name="date1" id="date1" placeholder="Start Date" value="<?php echo $this->dateTmp1; ?>"></input> to <input type="text" class="easyui-text" style="width:150px" name="date2" id="date2" placeholder="End date" value="<?php echo $this->dateTmp2; ?>"></input>
                        <button class="btn btn-success btn-sm" type="button" onclick="cari()">
                            Go
                        </button>
                    </div>
                </div>
        </form>
        <br>
        <table id="grid-table"></table>

        <div id="grid-pager"></div>

        
        <script type="text/javascript">
                var $path_base = "/";//this will be used in gritter alerts containing images
        </script>


        <div id="detail-form1" class="modal" tabindex="-1">
            <div class="modal-dialog">
                    <div class="modal-content">
                            <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                                    <h4 class="blue bigger">Withdraw Details Through Bank Wire</h4>
                            </div>

                            <div class="modal-body overflow-visible">
                                <div class="row">

                                    <div class="col-xs-11" id="row-content">
                                    
                                        <form id="formWD" class="form-horizontal" role="form" action="" method="post">
                                        <div class="form-group">
                                            <label class="col-sm-5 control-label no-padding-right" for="wallet"> Wallet </label>
                                            <div class="col-sm-7">
                                                    <input type="text" id="wallet" name="wallet" placeholder="0" class="col-xs-10 col-sm-11"  readonly  />
                                            </div>
                                        </div>
                                    
                                        <div class="form-group">
                                            <label class="col-sm-5 control-label no-padding-right" for="amount"> Amount </label>

                                            <div class="col-sm-7">
                                                <input type="text" id="amount" name="amount" placeholder="Number Only (Ex: 1500000)" class="col-xs-10 col-sm-11" readonly/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-5 control-label no-padding-right" for="acc_num"> Beneficiary's Account No </label>

                                            <div class="col-sm-7">
                                                <input type="text" id="acc_num" name="acc_num" placeholder="Beneficiary's Account No" class="col-xs-10 col-sm-11" readonly  />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-5 control-label no-padding-right" for="acc_name"> Beneficiary's Name </label>

                                            <div class="col-sm-7">
                                                <input type="text" id="acc_name" name="acc_name" placeholder="Beneficiary's Name" class="col-xs-10 col-sm-11" readonly />
                                            </div>
                                        </div>
                                            <div class="form-group">
                                                <label class="col-sm-5 control-label no-padding-right" for="acc_type"> Account Type </label>

                                                <div class="col-sm-7">
                                                    <input type="text" id="acc_type" name="acc_type" placeholder="Beneficiary's Name" class="col-xs-10 col-sm-11"  readonly  />
                                                </div>
                                            </div>
                                        <div class="form-group">
                                            <label class="col-sm-5 control-label no-padding-right" for="bank_name"> Beneficiary's Bank Name </label>

                                            <div class="col-sm-7">
                                                <input type="text" id="bank_name" name="bank_name" placeholder="Beneficiary's Bank Name" class="col-xs-10 col-sm-11" readonly />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-5 control-label no-padding-right" for="swift_code"> SWIFT Code / IBAN Number </label>

                                            <div class="col-sm-7">
                                                <input type="text" id="swift_code" name="swift_code" placeholder="SWIFT Code / IBAN Number" class="col-xs-10 col-sm-11" readonly  />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-5 control-label no-padding-right" for="address"> Beneficiary's Address </label>

                                            <div class="col-sm-7">
                                                <textarea id="address" name="address" class="autosize-transition form-control" placeholder="Beneficiary's Address" readonly></textarea>

                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-5 control-label no-padding-right" for="bank_addr"> Bank Address </label>

                                            <div class="col-sm-7">
                                                <textarea id="bank_addr" name="bank_addr" class="autosize-transition form-control" placeholder="Bank Address" readonly></textarea>

                                            </div>
                                        </div>
                                         <div class="form-group">
                                            <label class="col-sm-5 control-label no-padding-right" for="info"> Additional Information</label>

                                            <div class="col-sm-7">
                                                <textarea id="info" name="info" class="autosize-transition form-control" placeholder="Additional Information" readonly></textarea>

                                            </div>
                                        </div>
                                     </form>
                                
                                        
                                    </div>
                                    
                                </div>
                            </div>

                            <div class="modal-footer">
                                    <button class="btn btn-sm" data-dismiss="modal">
                                            <i class="icon-remove"></i>
                                            Close
                                    </button>

                                    
                            </div>
                    </div>
            </div>
    </div>

        <div id="detail-form2" class="modal" tabindex="-1">
            <div class="modal-dialog">
                    <div class="modal-content">
                            <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                                    <h4 class="blue bigger">Withdraw Details Through Perfect Money or Ego Pay</h4>
                            </div>

                            <div class="modal-body overflow-visible">
                                <div class="row">
                                    <div class="col-xs-11" id="row-content">
                                        <form id="formWD2" class="form-horizontal" role="form" action="" method="post">
                                        <div class="form-group">
                                            <label class="col-sm-5 control-label no-padding-right" for="wallet2"> Wallet </label>
                                            <div class="col-sm-7">
                                                    <input type="text" id="wallet2" name="wallet2" class="col-xs-10 col-sm-11" readonly />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-5 control-label no-padding-right" for="through"> Withdraw Through </label>
                                            <div class="col-sm-7">
                                                    <input type="text" id="through" name="through" class="col-xs-10 col-sm-11" readonly />
                                            </div>
                                        </div>
                                            <div class="form-group">
                                                <label class="col-sm-5 control-label no-padding-right" for="amount2"> Amount </label>

                                                <div class="col-sm-7">
                                                    <input type="text" id="amount2" name="amount2" placeholder="Number Only (Ex: 1500000)" class="col-xs-10 col-sm-11" readonly />
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-5 control-label no-padding-right" for="acc_num2"> Account No </label>

                                                <div class="col-sm-7">
                                                    <input type="text" id="acc_num2" name="acc_num2" placeholder="Account No" readonly class="col-xs-10 col-sm-11" />
                                                </div>
                                            </div>


                                        <div class="form-group">
                                            <label class="col-sm-5 control-label no-padding-right" for="acc_name2"> Account Name/Mail ID</label>

                                            <div class="col-sm-7">
                                                <input type="text" id="acc_name2" name="acc_name2" placeholder="Account Name/Mail ID" class="col-xs-10 col-sm-11" readonly />
                                            </div>
                                        </div>
                                      
                                        </form>
                                        
                                    </div>

                                </div>
                            </div>

                            <div class="modal-footer">
                                    <button class="btn btn-sm" data-dismiss="modal">
                                            <i class="icon-remove"></i>
                                            Close
                                    </button>


                            </div>
                    </div>
            </div>
    </div>

        <!-- PAGE CONTENT ENDS -->
    </div>
</div>


<script>

    var nowTemp = new Date();
    var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);

    var satrtDate = $('#date1').datepicker({
      format: 'yyyy-mm-dd'
    }).on('changeDate', function(ev) {
      //if (ev.date.valueOf() > endDate.date.valueOf()) {
        var newDate = new Date(ev.date)
        newDate.setDate(newDate.getDate() + 1);
        endDate.setValue(newDate);
      //}
      satrtDate.hide();
      $('#date2')[0].focus();
    }).data('datepicker');

    var endDate = $('#date2').datepicker({
      onRender: function(date) {
        return date.valueOf() <= satrtDate.date.valueOf() ? 'disabled' : '';
      }, format: 'yyyy-mm-dd'
    }).on('changeDate', function(ev) {
      endDate.hide();
    }).data('datepicker');


    jQuery(function($) {

            jQuery('#grid-table').jqGrid({
                url:'<?php echo $this->url() ?>/../../jsondata/trackingtrans?transType=T005',
                datatype: "json",
                height: 200,
                colNames:['Date','Account Number','Payment Gateway','Status','Amount','Details'],
                colModel:[
                    {name:'Tanggal',index:'trans_dat', width:300},
                    {name:'NoAkun',index:'account_num', width:300},
                    {name:'paymentgw',index:'paymentgw', width:300},
                    {name:'status',index:'status', width:300},
                    {name:'Debet',index:'amount', width:300, align:"right", formatter:"number"},
                    {name:'detail',index:'detail', width:300, align:"center"}
                ],
                rowNum:10,
                rowList:[10,20,30],
                pager: '#grid-pager',
                viewrecords: true,
                caption:"Withdraw Report",
                rownumbers: true,
                loadComplete : function() {
                        var table = this;
                        setTimeout(function(){
                                updateActionIcons(table);
                                updatePagerIcons(table);
                                enableTooltips(table);
                        }, 0);
                },

                autowidth: true
            });

            jQuery('#grid-table').jqGrid('navGrid','#grid-pager',{edit:false,add:false,del:false});


            //navButtons
            jQuery('#grid-table').jqGrid('navGrid','#grid-pager',
                    { 	//navbar options
                            search: true,
                            searchicon : 'ui-icon-search orange',
                            refresh: true,
                            refreshicon : 'ui-icon-refresh green'
                    }
            )




            //unlike navButtons icons, action icons in rows seem to be hard-coded
            //you can change them like this in here if you want
            function updateActionIcons(table) {

                    var replacement =
                    {
                            'ui-icon-search' : 'ui-icon-search orange',
                            'ui-icon-refresh' : 'ui-icon-refresh green'
                    };
                    $(table).find('.ui-pg-div span.ui-icon').each(function(){
                            var icon = $(this);
                            var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
                            if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
                    })

            }

            //replace icons with FontAwesome icons like above
            function updatePagerIcons(table) {
                    var replacement =
                    {
                            'ui-icon-seek-first' : 'icon-double-angle-left bigger-140',
                            'ui-icon-seek-prev' : 'icon-angle-left bigger-140',
                            'ui-icon-seek-next' : 'icon-angle-right bigger-140',
                            'ui-icon-seek-end' : 'icon-double-angle-right bigger-140'
                    };
                    $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function(){
                            var icon = $(this);
                            var $class = $.trim(icon.attr('class').replace('ui-icon', ''));

                            if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
                    })
            }

            function enableTooltips(table) {
                    $('.navtable .ui-pg-button').tooltip({container:'body'});
                    $(table).find('.ui-pg-div').tooltip({container:'body'});
            }

            //var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow');

    });

    function downloadExcel(){

        var num = jQuery('#grid-table').jqGrid('getGridParam','records');

        if (num > 0){

            $.ajax({
            type: 'GET',
            dataType: 'text',
            url: '<?php echo $this->url() ?>/../../excel/cetaksn',
            data: {num: num},
            success: function(result){

                        if (result == "TIMEOUT"){
                            location.href = "<?php echo $this->url() ?>/../../admin";
                        }else{
                            location.href = "<?php echo $this->url() ?>/../../excel/"+result;
                        }
                 }
            });

        }else alert('Tidak terdapat SN Baru, silahkan lakukan Generate SN terlebih dahulu.');

    }


    function cari(){

                var date1 = $('#date1').val();
                var date2 = $('#date2').val();
                
                jQuery("#grid-table").jqGrid('setGridParam',{
                    url:"<?php echo $this->url() ?>/../../jsondata/trackingtrans?transType=T005&date1="+date1+"&date2="+date2
                }).trigger("reloadGrid");

          

    }


    function detailTrans(res){

        var resJson = decode64(res);
        var data = JSON.parse(resJson);


        var tmp = "";

        var wallet = "";

        if (data.xn2 == 0) wallet = "E Wallet";
        else if (data.xn2 == 1) wallet = "ROI Wallet";
        else if (data.xn2 == 2) wallet = "Refferral Wallet";
        else if (data.xn2 == 3) wallet = "Binary Wallet";
        else wallet = "Shopping Wallet";

        if (data.xn1 == '1'){   //Bank Wire

            var accType = "";

            /*
            if (data.xn3 == 1) accType = "Bank Wire";
            else if (data.xn3 == 2) accType = "Paypall";
            else if (data.xn3 == 3) accType = "Perfect Money";
            else accType = "Ego Pay";
            */


            $('#wallet').val(wallet);
            $('#amount').val(data.amount1);
            $('#acc_num').val(data.xs1);
            $('#acc_name').val(data.xs2);
            $('#acc_type').val(data.paymentgw);
            $('#bank_name').val(data.xs3);
            $('#swift_code').val(data.xs4);
            $('#address').val(data.xs6);
            $('#bank_addr').val(data.xs5);
            $('#info').val(data.notes_txt);
        
        }else{

            //var through = (data.xn1 == '2') ? "Perfect Money" : "Ego Pay";

            $('#wallet2').val(wallet);
            $('#through').val(data.paymentgw);
            $('#amount2').val(data.amount1);
            $('#acc_num2').val(data.xs1);
            $('#acc_name2').val(data.xs2);

        }
        
    }


    function decode64(input) {
         var output = "";
         var chr1, chr2, chr3 = "";
         var enc1, enc2, enc3, enc4 = "";
         var i = 0;

         var keyStr = "ABCDEFGHIJKLMNOP" +
	               "QRSTUVWXYZabcdef" +
	               "ghijklmnopqrstuv" +
	               "wxyz0123456789+/" +
	               "=";

         // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
         var base64test = /[^A-Za-z0-9\+\/\=]/g;
         if (base64test.exec(input)) {
            alert("There were invalid base64 characters in the input text.\n" +
                  "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
                  "Expect errors in decoding.");
         }
         input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

         do {
            enc1 = keyStr.indexOf(input.charAt(i++));
            enc2 = keyStr.indexOf(input.charAt(i++));
            enc3 = keyStr.indexOf(input.charAt(i++));
            enc4 = keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
               output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
               output = output + String.fromCharCode(chr3);
            }

            chr1 = chr2 = chr3 = "";
            enc1 = enc2 = enc3 = enc4 = "";

         } while (i < input.length);

         return unescape(output);
     }



</script>




